import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { getDevLocation } from '@gis/lib/api';
import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import { openMonitorDetailsDialog } from '../../../../views/monitor/monitor-opt';
import get from 'lodash-es/get.js';
import { netAndScenicDataStore } from '@gis/lib/pinia/netAndScenic.js';

const sxtEnum = {
  D0112_6: 'gaopao',
  D0112_4: 'renlianzp',
  D0112_1: 'putongjk',
  D0112_9: 'aisfsxt',
};

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = sxtEnum[data.type];
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  getIconOption(icon) {
    return {
      content: `<div style="width: 52px;height: 96px;background: url(${icon}) center center no-repeat;background-size: 100% 100%"></div>`,
      offset: new AMap.Pixel(0, 0),
    };
  }
  onClick() {
    openMonitorDetailsDialog(this.data);
  }
}

export default class Cyspzy extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const { netYardIds, scenicIds } = netAndScenicDataStore();
    const data = await handleCommonRes(getDevLocation, {
      area_code: scenicIds ? scenicIds : area_code,
      yard_id: netYardIds,
      monitor_player: 'D0111_7', //猛追湾诚运平台、只看国祥监控视频
    });
    // D0112_6高空摄像 D0112_4人脸抓拍 D0112_1普通监控 D0112_9AI算法
    const xlgcType = get(data, 'xlgc_type', {});
    const pointList = Object.keys(xlgcType).reduce((res, item) => {
      const list = get(xlgcType, `${item}`, []);
      return res.concat(list);
    }, []);
    return pointList.map((item) => Object.assign({}, item, { lnglat: [item.longitude, item.latitude] }));
  }
}
